﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace syc.Store.报表
{
    public partial class 物资情况统计表 : System.Web.UI.Page
    {
        protected int month;
        protected double[] 套管光管本期收入=new double[12];
        protected double[] 套管光管本期发出 = new double[12];
        protected double[] 套管光管本期结存= new double[12];
        protected double 套管光管累计收入 = 0;
        protected double 套管光管累计发出 = 0;

        protected double[] N80套管光管本期收入 = new double[12];
        protected double[] N80套管光管本期发出 = new double[12];
        protected double[] N80套管光管本期结存 = new double[12];
        protected double N80套管光管累计收入 = 0;
        protected double N80套管光管累计发出 = 0;

        protected double[] 待处理套管光管本期收入 = new double[12];
        protected double[] 待处理套管光管本期发出 = new double[12];
        protected double[] 待处理套管光管本期结存 = new double[12];
        protected double 待处理套管光管累计收入 = 0;
        protected double 待处理套管光管累计发出 = 0;

        protected double[] N80待处理套管光管本期收入 = new double[12];
        protected double[] N80待处理套管光管本期发出 = new double[12];
        protected double[] N80待处理套管光管本期结存 = new double[12];
        protected double N80待处理套管光管累计收入 = 0;
        protected double N80待处理套管光管累计发出 = 0;

        protected double[] 套管接箍光管本期收入 = new double[12];
        protected double[] 套管接箍光管本期发出 = new double[12];
        protected double[] 套管接箍光管本期结存 = new double[12];
        protected double 套管接箍光管累计收入 = 0;
        protected double 套管接箍光管累计发出 = 0;

        protected double[] 成品套管接箍本期收入 = new double[12];
        protected double[] 成品套管接箍本期发出 = new double[12];
        protected double[] 成品套管接箍本期结存 = new double[12];
        protected double 成品套管接箍累计收入 = 0;
        protected double 成品套管接箍累计发出 = 0;

        protected double[] N80成品套管接箍本期收入 = new double[12];
        protected double[] N80成品套管接箍本期发出 = new double[12];
        protected double[] N80成品套管接箍本期结存 = new double[12];
        protected double N80成品套管接箍累计收入 = 0;
        protected double N80成品套管接箍累计发出 = 0;

        protected double[] 套管保护器本期收入 = new double[12];
        protected double[] 套管保护器本期发出 = new double[12];
        protected double[] 套管保护器本期结存 = new double[12];
        protected double 套管保护器累计收入 = 0;
        protected double 套管保护器累计发出 = 0;

        protected int[] 自产套管接箍本期收入 = new int[12];
        protected int[] 自产套管接箍本期发出 = new int[12];
        protected int[] 自产套管接箍本期结存 = new int[12];
        protected int 自产套管接箍累计收入 = 0;
        protected int 自产套管接箍累计发出 = 0;

        protected double[] 成品套管本期收入 = new double[12];
        protected double[] 成品套管本期发出 = new double[12];
        protected double[] 成品套管本期结存 = new double[12];
        protected double 成品套管累计收入 = 0;
        protected double 成品套管累计发出 = 0;

        protected double[] N80成品套管本期收入 = new double[12];
        protected double[] N80成品套管本期发出 = new double[12];
        protected double[] N80成品套管本期结存 = new double[12];
        protected double N80成品套管累计收入 = 0;
        protected double N80成品套管累计发出 = 0;

        protected double[] 保护涂料本期收入 = new double[12];
        protected double[] 保护涂料本期发出 = new double[12];
        protected double[] 保护涂料本期结存 = new double[12];
        protected double 保护涂料累计收入 = 0;
        protected double 保护涂料累计发出 = 0;

        protected double[] 螺纹脂本期收入 = new double[12];
        protected double[] 螺纹脂本期发出 = new double[12];
        protected double[] 螺纹脂本期结存 = new double[12];
        protected double 螺纹脂累计收入 = 0;
        protected double 螺纹脂累计发出 = 0;

        protected double[] 油管光管本期收入 = new double[12];
        protected double[] 油管光管本期发出 = new double[12];
        protected double[] 油管光管本期结存 = new double[12];
        protected double 油管光管累计收入 = 0;
        protected double 油管光管累计发出 = 0;

        protected double[] 待处理油管光管本期收入 = new double[12];
        protected double[] 待处理油管光管本期发出 = new double[12];
        protected double[] 待处理油管光管本期结存 = new double[12];
        protected double 待处理油管光管累计收入 = 0;
        protected double 待处理油管光管累计发出 = 0;
        //待处理接箍
        protected double[] 待处理油管接箍本期收入 = new double[12];
        protected double[] 待处理油管接箍本期发出 = new double[12];
        protected double[] 待处理油管接箍本期结存 = new double[12];
        protected double 待处理油管接箍累计收入 = 0;
        protected double 待处理油管接箍累计发出 = 0;

        protected double[] 待处理套管接箍本期收入 = new double[12];
        protected double[] 待处理套管接箍本期发出 = new double[12];
        protected double[] 待处理套管接箍本期结存 = new double[12];
        protected double 待处理套管接箍累计收入 = 0;
        protected double 待处理套管接箍累计发出 = 0;

        protected double[] 油管接箍光管本期收入 = new double[12];
        protected double[] 油管接箍光管本期发出 = new double[12];
        protected double[] 油管接箍光管本期结存 = new double[12];
        protected double 油管接箍光管累计收入 = 0;
        protected double 油管接箍光管累计发出 = 0;

        protected int[] 自产油管接箍本期收入 = new int[12];
        protected int[] 自产油管接箍本期发出 = new int[12];
        protected int[] 自产油管接箍本期结存 = new int[12];
        protected int 自产油管接箍累计收入 = 0;
        protected int 自产油管接箍累计发出 = 0;

        protected double[] 油管保护器本期收入 = new double[12];
        protected double[] 油管保护器本期发出 = new double[12];
        protected double[] 油管保护器本期结存 = new double[12];
        protected double 油管保护器累计收入 = 0;
        protected double 油管保护器累计发出 = 0;

        protected double[] 成品油管本期收入 = new double[12];
        protected double[] 成品油管本期发出 = new double[12];
        protected double[] 成品油管本期结存 = new double[12];
        protected double 成品油管累计收入 = 0;
        protected double 成品油管累计发出 = 0;

        protected double[] 打包带本期收入 = new double[12];
        protected double[] 打包带本期发出 = new double[12];
        protected double[] 打包带本期结存 = new double[12];
        protected double 打包带累计收入 = 0;
        protected double 打包带累计发出 = 0;

        protected double[] 草支垫本期收入 = new double[12];
        protected double[] 草支垫本期发出 = new double[12];
        protected double[] 草支垫本期结存 = new double[12];
        protected double 草支垫累计收入 = 0;
        protected double 草支垫累计发出 = 0;

        protected double[] 自产套管螺纹保护器本期收入 = new double[12];
        protected double[] 自产套管螺纹保护器本期发出 = new double[12];
        protected double[] 自产套管螺纹保护器本期结存 = new double[12];
        protected double 自产套管螺纹保护器累计收入 = 0;
        protected double 自产套管螺纹保护器累计发出 = 0;

        protected double[] 聚乙烯本期收入 = new double[12];
        protected double[] 聚乙烯本期发出 = new double[12];
        protected double[] 聚乙烯本期结存 = new double[12];
        protected double 聚乙烯累计收入 = 0;
        protected double 聚乙烯累计发出 = 0;

        protected double[] 钢带本期收入 = new double[12];
        protected double[] 钢带本期发出 = new double[12];
        protected double[] 钢带本期结存 = new double[12];
        protected double 钢带累计收入 = 0;
        protected double 钢带累计发出 = 0;

        protected double[] 车屑本期收入 = new double[12];
        protected double[] 车屑本期发出 = new double[12];
        protected double[] 车屑本期结存 = new double[12];
        protected double 车屑累计收入 = 0;
        protected double 车屑累计发出 = 0;

        protected double[] 切头本期收入 = new double[12];
        protected double[] 切头本期发出 = new double[12];
        protected double[] 切头本期结存 = new double[12];
        protected double 切头累计收入 = 0;
        protected double 切头累计发出 = 0;

        protected double[] 废打包带本期收入 = new double[12];
        protected double[] 废打包带本期发出 = new double[12];
        protected double[] 废打包带本期结存 = new double[12];
        protected double 废打包带累计收入 = 0;
        protected double 废打包带累计发出 = 0;


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.Year0.SelectedValue = DateTime.Today.Year.ToString();
                this.Month0.SelectedValue = DateTime.Today.Month.ToString();       
            }
            Button_Query_Click(null, null);
        }
        protected void Year0_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void Month0_SelectedIndexChanged(object sender, EventArgs e)
        {

        }       

        protected void Button_Query_Click(object sender, EventArgs e)
        {
            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            //原料
    
            for (int i = 1; i <= int.Parse(this.Month0.SelectedValue); i++)
            {   
                //套管胚料
                string sql = @"  select          
                dbo.原料本期收入(@年度,@月份,2),abs(dbo.原料本期发出(@年度,@月份,2)),dbo.原料期末库存(@年度,@月份,2)";
                sql = sql.Replace("@年度", this.Year0.SelectedValue);
                sql = sql.Replace("@月份",i.ToString());
                Cmd.CommandText = sql;
                SqlDataReader Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    套管光管本期收入[i - 1] = Reader.GetDouble(0);
                    套管光管本期发出[i - 1] = Reader.GetDouble(1);
                    套管光管本期结存[i - 1] = Reader.GetDouble(2);
                    套管光管累计收入 += 套管光管本期收入[i - 1];
                    套管光管累计发出 += 套管光管本期发出[i - 1];
                }
                Reader.Close();

                //N80套管胚料
                string sql0 = @"  select          
                dbo.原料本期收入(@年度,@月份,102),abs(dbo.原料本期发出(@年度,@月份,102)),dbo.原料期末库存(@年度,@月份,102)";
                sql0 = sql0.Replace("@年度", this.Year0.SelectedValue);
                sql0 = sql0.Replace("@月份", i.ToString());
                Cmd.CommandText = sql0;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    N80套管光管本期收入[i - 1] = Reader.GetDouble(0);
                    N80套管光管本期发出[i - 1] = Reader.GetDouble(1);
                    N80套管光管本期结存[i - 1] = Reader.GetDouble(2);
                    N80套管光管累计收入 += N80套管光管本期收入[i - 1];
                    N80套管光管累计发出 += N80套管光管本期发出[i - 1];
                }
                Reader.Close();
                //待处理套管胚料
                string sql2 = @"  select          
                dbo.待处理本期收入(@年度,@月份,2),dbo.待处理本期发出(@年度,@月份,2),dbo.待处理期末库存(@年度,@月份,2)";
                sql2 = sql2.Replace("@年度", this.Year0.SelectedValue);
                sql2 = sql2.Replace("@月份", i.ToString());
                Cmd.CommandText = sql2;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    待处理套管光管本期收入[i - 1] = Reader.GetDouble(0);
                    待处理套管光管本期发出[i - 1] = Reader.GetDouble(1);
                    待处理套管光管本期结存[i - 1] = Reader.GetDouble(2);
                    待处理套管光管累计收入 += 待处理套管光管本期收入[i - 1];
                    待处理套管光管累计发出 += 待处理套管光管本期发出[i - 1];
                }
                Reader.Close();

                //待处理N80套管胚料
                string sql200 = @"  select          
                dbo.待处理本期收入(@年度,@月份,102),dbo.待处理本期发出(@年度,@月份,102),dbo.待处理期末库存(@年度,@月份,102)";
                sql200 = sql200.Replace("@年度", this.Year0.SelectedValue);
                sql200 = sql200.Replace("@月份", i.ToString());
                Cmd.CommandText = sql200;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    N80待处理套管光管本期收入[i - 1] = Reader.GetDouble(0);
                    N80待处理套管光管本期发出[i - 1] = Reader.GetDouble(1);
                    N80待处理套管光管本期结存[i - 1] = Reader.GetDouble(2);
                    N80待处理套管光管累计收入 += N80待处理套管光管本期收入[i - 1];
                    N80待处理套管光管累计发出 += N80待处理套管光管本期发出[i - 1];
                }
                Reader.Close();
                //套管接箍胚料
                string sql3 = @"  select          
                dbo.原料本期收入(@年度,@月份,4),abs(dbo.原料本期发出(@年度,@月份,4)),dbo.原料期末库存(@年度,@月份,4)";
                sql3 = sql3.Replace("@年度", this.Year0.SelectedValue);
                sql3 = sql3.Replace("@月份", i.ToString());
                Cmd.CommandText = sql3;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    套管接箍光管本期收入[i - 1] = Reader.GetDouble(0);
                    套管接箍光管本期发出[i - 1] = Reader.GetDouble(1);
                    套管接箍光管本期结存[i - 1] = Reader.GetDouble(2);
                    套管接箍光管累计收入 += 套管接箍光管本期收入[i - 1];
                    套管接箍光管累计发出 += 套管接箍光管本期发出[i - 1];
                }
                Reader.Close();
                //成品套管接箍
                string sql4 = @"  select          
                dbo.原料本期收入(@年度,@月份,6),abs(dbo.原料本期发出(@年度,@月份,6)),dbo.原料期末库存(@年度,@月份,6)";
                sql4 = sql4.Replace("@年度", this.Year0.SelectedValue);
                sql4 = sql4.Replace("@月份", i.ToString());
                Cmd.CommandText = sql4;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    成品套管接箍本期收入[i - 1] = Reader.GetDouble(0);
                    成品套管接箍本期发出[i - 1] = Reader.GetDouble(1);
                    成品套管接箍本期结存[i - 1] = Reader.GetDouble(2);
                    成品套管接箍累计收入 += 成品套管接箍本期收入[i - 1];
                    成品套管接箍累计发出 += 成品套管接箍本期发出[i - 1];
                }
                Reader.Close();
                //N80成品套管接箍
                string sql400 = @"  select          
                dbo.原料本期收入(@年度,@月份,106),abs(dbo.原料本期发出(@年度,@月份,106)),dbo.原料期末库存(@年度,@月份,106)";
                sql400 = sql400.Replace("@年度", this.Year0.SelectedValue);
                sql400 = sql400.Replace("@月份", i.ToString());
                Cmd.CommandText = sql4;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    N80成品套管接箍本期收入[i - 1] = Reader.GetDouble(0);
                    N80成品套管接箍本期发出[i - 1] = Reader.GetDouble(1);
                    N80成品套管接箍本期结存[i - 1] = Reader.GetDouble(2);
                    N80成品套管接箍累计收入 += N80成品套管接箍本期收入[i - 1];
                    N80成品套管接箍累计发出 += N80成品套管接箍本期发出[i - 1];
                }
                Reader.Close();
                //套管螺纹保护环
                 string sql5 = @"  select          
                dbo.材料本期收入(@年度,@月份,0700000002),abs(dbo.材料本期发出(@年度,@月份,0700000002)),dbo.材料期末库存(@年度,@月份,0700000002)";
                sql5 = sql5.Replace("@年度", this.Year0.SelectedValue);
                sql5 = sql5.Replace("@月份", i.ToString());
                Cmd.CommandText = sql5;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    套管保护器本期收入[i - 1] = Reader.GetDouble(0);
                    套管保护器本期发出[i - 1] = Reader.GetDouble(1);
                    套管保护器本期结存[i - 1] = Reader.GetDouble(2);
                    套管保护器累计收入 += 套管保护器本期收入[i - 1];
                    套管保护器累计发出 += 套管保护器本期发出[i - 1];
                }
                Reader.Close();
                //自产套管接箍
                string sql6 = @"  select          
                dbo.自产接箍本期收入(@年度,@月份,2),abs(dbo.自产接箍本期发出(@年度,@月份,2)),dbo.自产接箍期末库存(@年度,@月份,2)";
                sql6 = sql6.Replace("@年度", this.Year0.SelectedValue);
                sql6 = sql6.Replace("@月份", i.ToString());
                Cmd.CommandText = sql6;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    自产套管接箍本期收入[i - 1] = Reader.GetInt32(0);
                    自产套管接箍本期发出[i - 1] = Reader.GetInt32(1);
                    自产套管接箍本期结存[i - 1] = Reader.GetInt32(2);
                    自产套管接箍累计收入 += 自产套管接箍本期收入[i - 1];
                    自产套管接箍累计发出 += 自产套管接箍本期发出[i - 1];
                }
                Reader.Close();
                //成品套管
                string sql7 = @"  select          
                dbo.产品本期收入(@年度,@月份,2,0),abs(dbo.产品本期发出(@年度,@月份,2,0)),dbo.产品本期结存(@年度,@月份,2,0)";
                sql7 = sql7.Replace("@年度", this.Year0.SelectedValue);
                sql7 = sql7.Replace("@月份", i.ToString());
                Cmd.CommandText = sql7;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    成品套管本期收入[i - 1] = Reader.GetDouble(0);
                    成品套管本期发出[i - 1] = Reader.GetDouble(1);
                    成品套管本期结存[i - 1] = Reader.GetDouble(2);
                    成品套管累计收入 += 成品套管本期收入[i - 1];
                    成品套管累计发出 += 成品套管本期发出[i - 1];
                }
                Reader.Close();
                //N80成品套管
                string sql700 = @"  select          
                dbo.产品本期收入(@年度,@月份,4,0),abs(dbo.产品本期发出(@年度,@月份,4,0)),dbo.产品本期结存(@年度,@月份,4,0)";
                sql700 = sql700.Replace("@年度", this.Year0.SelectedValue);
                sql700 = sql700.Replace("@月份", i.ToString());
                Cmd.CommandText = sql700;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    N80成品套管本期收入[i - 1] = Reader.GetDouble(0);
                    N80成品套管本期发出[i - 1] = Reader.GetDouble(1);
                    N80成品套管本期结存[i - 1] = Reader.GetDouble(2);
                    N80成品套管累计收入 += N80成品套管本期收入[i - 1];
                    N80成品套管累计发出 += N80成品套管本期发出[i - 1];
                }
                Reader.Close();
                //保护涂料
                string sql8 = @"  select          
                dbo.材料本期收入(@年度,@月份,0301000001)+dbo.材料本期收入(@年度,@月份,0301000002),abs(dbo.材料本期发出(@年度,@月份,0301000001)+dbo.材料本期发出(@年度,@月份,0301000002)),dbo.材料期末库存(@年度,@月份,0301000001)+dbo.材料期末库存(@年度,@月份,0301000002)";
                sql8 = sql8.Replace("@年度", this.Year0.SelectedValue);
                sql8 = sql8.Replace("@月份", i.ToString());
                Cmd.CommandText = sql8;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    保护涂料本期收入[i - 1] = Reader.GetDouble(0);
                    保护涂料本期发出[i - 1] = Reader.GetDouble(1);
                    保护涂料本期结存[i - 1] = Reader.GetDouble(2);
                    保护涂料累计收入 += 保护涂料本期收入[i - 1];
                    保护涂料累计发出 += 保护涂料本期发出[i - 1];
                }
                Reader.Close();
                //螺纹脂
                string sql9 = @"  select          
                dbo.材料本期收入(@年度,@月份,0302000001),abs(dbo.材料本期发出(@年度,@月份,0302000001)),dbo.材料期末库存(@年度,@月份,0302000001)";
                sql9 = sql9.Replace("@年度", this.Year0.SelectedValue);
                sql9 = sql9.Replace("@月份", i.ToString());
                Cmd.CommandText = sql9;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    螺纹脂本期收入[i - 1] = Reader.GetDouble(0);
                    螺纹脂本期发出[i - 1] = Reader.GetDouble(1);
                    螺纹脂本期结存[i - 1] = Reader.GetDouble(2);
                    螺纹脂累计收入 += 螺纹脂本期收入[i - 1];
                    螺纹脂累计发出 += 螺纹脂本期发出[i - 1];
                }
                Reader.Close();

                //油管胚料
                string sql10 = @"  select          
                dbo.原料本期收入(@年度,@月份,1),abs(dbo.原料本期发出(@年度,@月份,1)),dbo.原料期末库存(@年度,@月份,1)";
                sql10 = sql10.Replace("@年度", this.Year0.SelectedValue);
                sql10 = sql10.Replace("@月份", i.ToString());
                Cmd.CommandText = sql10;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    油管光管本期收入[i - 1] = Reader.GetDouble(0);
                    油管光管本期发出[i - 1] = Reader.GetDouble(1);
                    油管光管本期结存[i - 1] = Reader.GetDouble(2);
                    油管光管累计收入 += 油管光管本期收入[i - 1];
                    油管光管累计发出 += 油管光管本期发出[i - 1];
                }
                Reader.Close();
                //待处理油管胚料
                string sql11 = @"  select          
                dbo.待处理本期收入(@年度,@月份,1),dbo.待处理本期发出(@年度,@月份,1),dbo.待处理期末库存(@年度,@月份,1)";
                sql11 = sql11.Replace("@年度", this.Year0.SelectedValue);
                sql11 = sql11.Replace("@月份", i.ToString());
                Cmd.CommandText = sql11;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    待处理油管光管本期收入[i - 1] = Reader.GetDouble(0);
                    待处理油管光管本期发出[i - 1] = Reader.GetDouble(1);
                    待处理油管光管本期结存[i - 1] = Reader.GetDouble(2);
                    待处理油管光管累计收入 += 待处理油管光管本期收入[i - 1];
                    待处理油管光管累计发出 += 待处理油管光管本期发出[i - 1];
                }
                Reader.Close();
                //油管接箍胚料
                string sql12= @"  select          
                dbo.原料本期收入(@年度,@月份,3),abs(dbo.原料本期发出(@年度,@月份,3)),dbo.原料期末库存(@年度,@月份,3)";
                sql12 = sql12.Replace("@年度", this.Year0.SelectedValue);
                sql12 = sql12.Replace("@月份", i.ToString());
                Cmd.CommandText = sql12;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    油管接箍光管本期收入[i - 1] = Reader.GetDouble(0);
                    油管接箍光管本期发出[i - 1] = Reader.GetDouble(1);
                    油管接箍光管本期结存[i - 1] = Reader.GetDouble(2);
                    油管接箍光管累计收入 += 油管接箍光管本期收入[i - 1];
                    油管接箍光管累计发出 += 油管接箍光管本期发出[i - 1];
                }
                Reader.Close();
                //自产油管接箍
                string sql13 = @"  select          
                dbo.自产接箍本期收入(@年度,@月份,1),abs(dbo.自产接箍本期发出(@年度,@月份,1)),dbo.自产接箍期末库存(@年度,@月份,1)";
                sql13 = sql13.Replace("@年度", this.Year0.SelectedValue);
                sql13 = sql13.Replace("@月份", i.ToString());
                Cmd.CommandText = sql13;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    自产油管接箍本期收入[i - 1] = Reader.GetInt32(0);
                    自产油管接箍本期发出[i - 1] = Reader.GetInt32(1);
                    自产油管接箍本期结存[i - 1] = Reader.GetInt32(2);
                    自产油管接箍累计收入 += 自产油管接箍本期收入[i - 1];
                    自产油管接箍累计发出 += 自产油管接箍本期发出[i - 1];
                }
                Reader.Close();
                //油管螺纹保护环
                string sql14 = @"  select          
                dbo.材料本期收入(@年度,@月份,0700000001),abs(dbo.材料本期发出(@年度,@月份,0700000001)),dbo.材料期末库存(@年度,@月份,0700000001)";
                sql14 = sql14.Replace("@年度", this.Year0.SelectedValue);
                sql14 = sql14.Replace("@月份", i.ToString());
                Cmd.CommandText = sql14;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    油管保护器本期收入[i - 1] = Reader.GetDouble(0);
                    油管保护器本期发出[i - 1] = Reader.GetDouble(1);
                    油管保护器本期结存[i - 1] = Reader.GetDouble(2);
                    油管保护器累计收入 += 油管保护器本期收入[i - 1];
                    油管保护器累计发出 += 油管保护器本期发出[i - 1];
                }
                Reader.Close();
                //成品油管
                string sql15= @"  select          
                dbo.产品本期收入(@年度,@月份,1,0),abs(dbo.产品本期发出(@年度,@月份,1,0)),dbo.产品本期结存(@年度,@月份,1,0)";
                sql15 = sql15.Replace("@年度", this.Year0.SelectedValue);
                sql15 = sql15.Replace("@月份", i.ToString());
                Cmd.CommandText = sql15;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    成品油管本期收入[i - 1] = Reader.GetDouble(0);
                    成品油管本期发出[i - 1] = Reader.GetDouble(1);
                    成品油管本期结存[i - 1] = Reader.GetDouble(2);
                    成品油管累计收入 += 成品油管本期收入[i - 1];
                    成品油管累计发出 += 成品油管本期发出[i - 1];
                }
                Reader.Close();
                //打包带
                string sql16 = @"  select          
                dbo.材料本期收入(@年度,@月份,0401000001),abs(dbo.材料本期发出(@年度,@月份,0401000001)),dbo.材料期末库存(@年度,@月份,0401000001)";
                sql16= sql16.Replace("@年度", this.Year0.SelectedValue);
                sql16 = sql16.Replace("@月份", i.ToString());
                Cmd.CommandText = sql16;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    打包带本期收入[i - 1] = Reader.GetDouble(0);
                    打包带本期发出[i - 1] = Reader.GetDouble(1);
                    打包带本期结存[i - 1] = Reader.GetDouble(2);
                    打包带累计收入 += 打包带本期收入[i - 1];
                    打包带累计发出 += 打包带本期发出[i - 1];
                }
                Reader.Close();
                //草支垫
                string sql17 = @"  select          
                dbo.材料本期收入(@年度,@月份,0700000003),abs(dbo.材料本期发出(@年度,@月份,0700000003)),dbo.材料期末库存(@年度,@月份,0700000003)";
                sql17 = sql17.Replace("@年度", this.Year0.SelectedValue);
                sql17 = sql17.Replace("@月份", i.ToString());
                Cmd.CommandText = sql17;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    草支垫本期收入[i - 1] = Reader.GetDouble(0);
                    草支垫本期发出[i - 1] = Reader.GetDouble(1);
                    草支垫本期结存[i - 1] = Reader.GetDouble(2);
                    草支垫累计收入 += 草支垫本期收入[i - 1];
                    草支垫累计发出 += 草支垫本期发出[i - 1];
                }
                Reader.Close();
                //自产套管螺纹保护器             
                string sql18 = @"  select          
                dbo.自产保护器本期收入(@年度,@月份,2),abs(dbo.自产保护器本期发出(@年度,@月份,2)),dbo.自产保护器期末库存(@年度,@月份,2)";
                sql18 = sql18.Replace("@年度", this.Year0.SelectedValue);
                sql18 = sql18.Replace("@月份", i.ToString());
                Cmd.CommandText = sql18;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    自产套管螺纹保护器本期收入[i - 1] = Reader.GetDouble(0);
                    自产套管螺纹保护器本期发出[i - 1] = Reader.GetDouble(1);
                    自产套管螺纹保护器本期结存[i - 1] = Reader.GetDouble(2);
                    自产套管螺纹保护器累计收入 += 自产套管螺纹保护器本期收入[i - 1];
                    自产套管螺纹保护器累计发出 += 自产套管螺纹保护器本期发出[i - 1];
                }
                Reader.Close();

                //聚乙烯
                string sql22 = @"  select          
                dbo.材料本期收入(@年度,@月份,0301000007),abs(dbo.材料本期发出(@年度,@月份,0301000007)),dbo.材料期末库存(@年度,@月份,0301000007)";
                sql22 = sql22.Replace("@年度", this.Year0.SelectedValue);
                sql22 = sql22.Replace("@月份", i.ToString());
                Cmd.CommandText = sql22;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    聚乙烯本期收入[i - 1] = Reader.GetDouble(0);
                    聚乙烯本期发出[i - 1] = Reader.GetDouble(1);
                    聚乙烯本期结存[i - 1] = Reader.GetDouble(2);
                    聚乙烯累计收入 += 聚乙烯本期收入[i - 1];
                    聚乙烯累计发出 += 聚乙烯本期发出[i - 1];
                }
                Reader.Close();
                //钢带
                string sql23 = @"  select          
                dbo.材料本期收入(@年度,@月份,0401000002),abs(dbo.材料本期发出(@年度,@月份,0401000002)),dbo.材料期末库存(@年度,@月份,0401000002)";
                sql23 = sql23.Replace("@年度", this.Year0.SelectedValue);
                sql23 = sql23.Replace("@月份", i.ToString());
                Cmd.CommandText = sql23;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    钢带本期收入[i - 1] = Reader.GetDouble(0);
                    钢带本期发出[i - 1] = Reader.GetDouble(1);
                    钢带本期结存[i - 1] = Reader.GetDouble(2);
                    钢带累计收入 += 钢带本期收入[i - 1];
                    钢带累计发出 += 钢带本期发出[i - 1];
                }
                Reader.Close();
                //废料车削
                string sql24= @"  select          
                dbo.废料本期收入(@年度,@月份,1)";
                sql24 = sql24.Replace("@年度", this.Year0.SelectedValue);
                sql24 = sql24.Replace("@月份", i.ToString());
                Cmd.CommandText = sql24;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    车屑本期收入[i - 1] = Reader.GetDouble(0);
                    车屑本期发出[i - 1] = Reader.GetDouble(0);
                    车屑本期结存[i - 1] = 车屑本期收入[i - 1] - 车屑本期发出[i - 1];
                    车屑累计收入 += 车屑本期收入[i - 1];
                    车屑累计发出 += 车屑本期发出[i - 1];
                }
                Reader.Close();
                //废料打包带
                string sql25 = @"  select          
                dbo.废料本期收入(@年度,@月份,2)";
                sql25 = sql25.Replace("@年度", this.Year0.SelectedValue);
                sql25 = sql25.Replace("@月份", i.ToString());
                Cmd.CommandText = sql25;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    废打包带本期收入[i - 1] = Reader.GetDouble(0);
                    废打包带本期发出[i - 1] = Reader.GetDouble(0);
                    废打包带本期结存[i - 1] = 废打包带本期收入[i - 1] - 废打包带本期发出[i - 1];
                    废打包带累计收入 += 废打包带本期收入[i - 1];
                    废打包带累计发出 += 废打包带本期发出[i - 1];
                }
                Reader.Close();
                //废料切头
                string sql26 = @"  select          
                dbo.废料本期收入(@年度,@月份,3)";
                sql26 = sql26.Replace("@年度", this.Year0.SelectedValue);
                sql26 = sql26.Replace("@月份", i.ToString());
                Cmd.CommandText = sql26;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    切头本期收入[i - 1] = Reader.GetDouble(0);
                    切头本期发出[i - 1] = Reader.GetDouble(0);
                    切头本期结存[i - 1] = 切头本期收入[i - 1] - 切头本期发出[i - 1];
                    切头累计收入 += 切头本期收入[i - 1];
                    切头累计发出 += 切头本期发出[i - 1];
                }
                Reader.Close();
               
                //待处理油管接箍胚料
                string sql27 = @"  select          
                dbo.待处理本期收入(@年度,@月份,3),dbo.待处理本期发出(@年度,@月份,3),dbo.待处理期末库存(@年度,@月份,3)";
                sql27 = sql27.Replace("@年度", this.Year0.SelectedValue);
                sql27 = sql27.Replace("@月份", i.ToString());
                Cmd.CommandText = sql27;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    待处理油管接箍本期收入[i - 1] = Reader.GetDouble(0);
                    待处理油管接箍本期发出[i - 1] = Reader.GetDouble(1);
                    待处理油管接箍本期结存[i - 1] = Reader.GetDouble(2);
                    待处理油管接箍累计收入 += 待处理油管接箍本期收入[i - 1];
                    待处理油管接箍累计发出 += 待处理油管接箍本期发出[i - 1];
                }
                Reader.Close();

                string sql28 = @"  select          
                dbo.待处理本期收入(@年度,@月份,4),dbo.待处理本期发出(@年度,@月份,4),dbo.待处理期末库存(@年度,@月份,4)";
                sql28 = sql28.Replace("@年度", this.Year0.SelectedValue);
                sql28 = sql28.Replace("@月份", i.ToString());
                Cmd.CommandText = sql28;
                Reader = Cmd.ExecuteReader();
                if (Reader.Read())
                {
                    待处理套管接箍本期收入[i - 1] = Reader.GetDouble(0);
                    待处理套管接箍本期发出[i - 1] = Reader.GetDouble(1);
                    待处理套管接箍本期结存[i - 1] = Reader.GetDouble(2);
                    待处理套管接箍累计收入 += 待处理套管接箍本期收入[i - 1];
                    待处理套管接箍累计发出 += 待处理套管接箍本期发出[i - 1];
                }
                Reader.Close();

            }
           
            Cmd.Dispose();
            Conn.Dispose();
        }

        protected void Button_Save_Click(object sender, EventArgs e)
        {

        }
    }
}

